package com.ysqcould.web.controller.message;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ysqcould.message.domain.SmsApp;
import com.ysqcould.message.service.ISmsAppService;

/**
 * 发送短信的小程序Controller
 * 
 * @author jcd
 * @date 2022-09-21
 */
@RestController
@RequestMapping("/message/app")
public class SmsAppController extends BaseController
{
    @Autowired
    private ISmsAppService smsAppService;

    /**
     * 查询发送短信的小程序列表
     */
    @PreAuthorize("@ss.hasPermi('message:app:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmsApp smsApp)
    {
        startPage();
        List<SmsApp> list = smsAppService.selectSmsAppList(smsApp);
        return getDataTable(list);
    }

    /**
     * 导出发送短信的小程序列表
     */
    @PreAuthorize("@ss.hasPermi('message:app:export')")
    @Log(title = "发送短信的小程序", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SmsApp smsApp)
    {
        List<SmsApp> list = smsAppService.selectSmsAppList(smsApp);
        ExcelUtil<SmsApp> util = new ExcelUtil<SmsApp>(SmsApp.class);
        util.exportExcel(response, list, "发送短信的小程序数据");
    }

    /**
     * 获取发送短信的小程序详细信息
     */
    @PreAuthorize("@ss.hasPermi('message:app:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(smsAppService.selectSmsAppById(id));
    }

    /**
     * 新增发送短信的小程序
     */
    @PreAuthorize("@ss.hasPermi('message:app:add')")
    @Log(title = "发送短信的小程序", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmsApp smsApp)
    {
        return toAjax(smsAppService.insertSmsApp(smsApp));
    }

    /**
     * 修改发送短信的小程序
     */
    @PreAuthorize("@ss.hasPermi('message:app:edit')")
    @Log(title = "发送短信的小程序", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmsApp smsApp)
    {
        return toAjax(smsAppService.updateSmsApp(smsApp));
    }

    /**
     * 删除发送短信的小程序
     */
    @PreAuthorize("@ss.hasPermi('message:app:remove')")
    @Log(title = "发送短信的小程序", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(smsAppService.deleteSmsAppByIds(ids));
    }
}
